package handin04;

import javax.swing.JOptionPane;

/**
 * PrimeGeneratorRunner runs PrimeGenerator and PrimeGeneratorView
 * 
 * @author Peter Tolstrup Aagesen, ptaa@itu.dk
 *
 */

public class PrimeGeneratorRunner {

	public static void main(String[] args) {
		//Prompt the user for input
		String input = JOptionPane.showInputDialog("Enter a method and a number. \nThe number can be any positive integer. \nThe method is either 'test' or 'list' \nExample: 'test 1337'");
		
		//Get method part
		String methodInput = input.substring(0, input.indexOf(' '));
		//Get number part
		String numberInput = input.substring(input.indexOf(' ') + 1);
		int number = Integer.parseInt(numberInput);
		
		//Print prime list to console
		PrimeGenerator.nextPrime(number);
		
		//Create PrimeGeneratorView
		PrimeGeneratorView view = new PrimeGeneratorView();
		
		//Test which method to use
		if(methodInput.toLowerCase().equals("test")){
			view.isPrime(number);
		} else if(methodInput.toLowerCase().equals("list")){
			view.nextPrime(number);
		}
	}
}
